package com.example.chatweb.controller;

import com.example.chatweb.entity.Opinion;
import com.example.chatweb.service.OpinionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class OpinionController {

    private final OpinionService opinionService;

    @Autowired
    public OpinionController(OpinionService opinionService) {
        this.opinionService = opinionService;
    }

    @PostMapping("/insert_opinion")
    public void insert(@RequestBody Opinion opinion){
        System.out.println(opinion.getFileId());
        System.out.println(opinion.getContent());
        opinionService.addOpinion(opinion);
    }
    @PostMapping("/update_opinion")
    public void addOrupdate(@RequestBody Opinion opinion){
        opinionService.addOrUpdateOpinion(opinion);
    }
    @GetMapping("getContent")
    public String getContent(@RequestParam("fileId") Integer fileId){
        return opinionService.getContentByID(fileId);
    }
}
